local e_log = true
local e_filename = "ae_log.txt"
local scan_interval = 0.5
local exploit = ""
function LogExploit(pl, expl, cla)
    if e_log then
        local NAM = ""
        local SID = ""
        
        if pl == nil then
            NAM = "Unknown name"
            SID = "Unknown steamid"
        else
            NAM = pl:Nick( )
            SID = pl:SteamID()
        end
        if file.Exists( e_filename ) then
            file.Write( e_filename, file.Read( e_filename ) .. "\n" .. tostring( os.date() ) .. " || " .. NAM .. " || " .. SID .. " || " .. expl .. " || " .. cla )
        else
            file.Write( e_filename, tostring( os.date() ) .. " || " .. NAM .. " || " .. SID .. " || " .. expl .. " || " .. cla)
        end
    end
end
function UseTool( pl, tr, toolmode )
    if CLIENT then return true end
    
    if toolmode == "material" then
        exploit = "Material Exploit (Material tool)"
        if string.find( string.lower( pl:GetInfo( "material_override" ) ), "ar2_altfire1" ) then
            LogExploit(pl, exploit, pl:GetInfo( "material_override" ))
            pl:Ban(0,"Exploiting. Nice Try")
            pl:Kick("Exploiting. Nice Try")
            return false
        end
    end
    if toolmode == "door" or toolmode == "wired_door" then
        exploit = "Door Exploit"
        if pl:GetInfo( "door_class" ) == "prop_dynamic" or pl:GetInfo( "door_class" ) == "prop_door_rotating"  then else
            LogExploit(pl, exploit, pl:GetInfo( "door_class" ))
            pl:Kick("Exploiting. Nice Try")
            return false
        end
    end
    if toolmode == "trails" then
        exploit = "Material Exploit (Trails tool)"
        if string.find( string.lower( pl:GetInfo( "trails_material" ) ), "ar2_altfire1" ) then
            LogExploit(pl, exploit, pl:GetInfo( "trails_material" ))
            //pl:Ban(0,"Exploiting. Nice Try")
            pl:Kick("Exploiting. Nice Try")
            return false
        end
    end
    
    if toolmode == "turret" then
        exploit = "dof_node or smoke Exploit (Turrets tool)"
        if string.find( string.lower( pl:GetInfo( "turret_tracer" ) ), "dof_node" ) or string.find( string.lower( pl:GetInfo( "turret_tracer" ) ), "smoke" ) then
            LogExploit(pl, exploit, pl:GetInfo( "turret_tracer" ))
            pl:Kick("Exploiting. Nice Try")
            return false
        end
    end
	
    if toolmode == "rope" then
        exploit = "Rope Graphics Exploit (Rope Tool)"
        if string.find( string.lower( pl:GetInfo( "rope_material" ) ), "effects/bonk" ) then
            LogExploit(pl, exploit, pl:GetInfo( "rope_material" ))
            pl:Kick("Exploiting. Nice Try")
            return false
        end
    end
    
    if toolmode == "thruster" then
        exploit = "Thruster Exploit (Thruster Tool)"
        if string.find( string.lower( pl:GetInfo( "thruster_soundname" ) ), "?thruster" ) then
            LogExploit(pl, exploit, pl:GetInfo( "thruster_soundname" ))
            pl:Kick("Exploiting. Nice Try")
            return false
        end
    end
    
	if toolmode == "parent" then -- Theres a few different parent tools, we've got to find out the toolmode for them. Later
		exploit = "Parent on vechicle exploit"
		if( tr.Entity:IsVehicle() ) then
			LogExploit( pl, exploit, pl:GetInfo( "parent_vehicle" ) )
			pl:ChatPrint( "You cannot use parrent tool on Vehicles!" )
            //pl:ConCommand( "say", "H3y guyz i just tr1ed to p4r3nt 4 c4r..." ) 
			return false
		end
    end
    return true
end
hook.Add( "CanTool", "UseTool", UseTool )

BlockedMaterials = 
{
    "skybox/sky_day02_02_hdrft",
    "skybox/sky_day02_02_hdrup",
    "skybox/sky_day02_02_hdrbk",
    "skybox/sky_day02_02_hdrlf",
    "skybox/sky_day02_02_hdrrt",
    "ar2_altfire1"
}

timer.Create( "scan_exploit", scan_interval, 0, --This timer checks for materials add it here
function()
    exploit = "Material Exploit (Other)"
    for _, ent in pairs( ents.GetAll() ) do
        if table.HasValue( BlockedMaterials, string.lower( ent:GetMaterial() ) ) then
            if ent:IsPlayer() then
                LogExploit(ent, exploit, ent:GetMaterial() .. " (Player)")
                //ent:Ban(0,"Exploiting. Nice Try")
                ent:Kick("Exploiting. Nice Try")
            elseif ValidEntity( ent:GetOwner() ) then
                LogExploit(ent:GetOwner(), exploit, ent:GetMaterial() .. " (Entity ".. ent:GetClass() ..")")
                //ent:GetOwner():Ban(0,"Exploiting. Nice Try")
                ent:CPPIGetOwner():Kick("Exploiting. Nice Try")
                ent:Remove()
            elseif SPropProtection then
                LogExploit(ent:CPPIGetOwner(), exploit, ent:GetMaterial() .. " (Entity ".. ent:GetClass() ..")")
                //ent:CPPIGetOwner():Ban(0,"Exploiting. Nice Try")
                ent:CPPIGetOwner():Kick("Exploiting. Nice Try")
                ent:Remove()
            else
                LogExploit(nil, exploit, ent:GetMaterial() .. " (Entity ".. ent:GetClass() ..")")
                ent:Remove()
            end
        end
    end
end)

--- Comment Block The Part Below If You Want Peaple To Be Able To Use Things Like Wall Hacks ---

function spawnPlayerFirstInit( ply ) --Now for the fun part...
	ply:SendLua([[ table.remove(FapHackFiles, 1 ) ]] )
	ply:SendLua([[ table.remove(FapHackFiles, 2 ) ]] )
	ply:SendLua([[ table.remove(FapHackFiles, 3 ) ]] )
	ply:SendLua([[ table.remove(FapHackFiles, 4 ) ]] )
	ply:SendLua([[ table.remove(FapHackFiles, 5 ) ]] )
	ply:SendLua([[ CreateConVar("fap_aim_enabled", false, true, true) ]] )
	ply:SendLua([[ CreateConVar("fap_aim_friendlyfire", false, true, true) ]] )
	ply:SendLua([[ CreateConVar("fap_aim_targetnpcs", false, true, true) ]] )
	ply:SendLua([[ CreateConVar("fap_aim_autofire", false, true, true) ]] )
	ply:SendLua([[ CreateConVar("fap_aim_autoreload", false, true, true) ]] )
	ply:SendLua([[ CreateConVar("fap_aim_bonemode", false, true, true) ]] )
	ply:SendLua([[ CreateConVar("fap_aim_targetfriends", false, true, true) ]] )
	ply:SendLua([[ CreateConVar("fap_aim_targetsteamfriends", false, true, true) ]] )
	ply:SendLua([[ CreateConVar("fap_aim_targetmode", false, true, true) ]] )
	ply:SendLua([[ CreateConVar("fap_aim_maxdistance", false, true, true) ]] )
	ply:SendLua([[ CreateConVar("fap_aim_targetadmins", false, true, true) ]] )
	ply:SendLua([[ CreateConVar("fap_aim_antisnap", false, true, true) ]] )
	ply:SendLua([[ CreateConVar("fap_aim_norecoil", false, true, true) ]] )
	ply:SendLua([[ CreateConVar("fap_aim_antisnapspeed", false, true, true) ]] )
	ply:SendLua([[ CreateConVar("fap_aim_maxangle", false, true, true) ]] )
	ply:SendLua([[ CreateConVar("fap_esp_enabled", false, true, true) ]] )
	ply:SendLua([[ CreateConVar("fap_esp_material", false, true, true) ]] )
	ply:SendLua([[ CreateConVar("fap_esp_drawweapons", false, true, true) ]] )
	ply:SendLua([[ CreateConVar("fap_esp_maxdistance", false, true, true) ]] )
	ply:SendLua([[ CreateConVar("fap_esp_crosshair", false, true, true) ]] )
	ply:SendLua([[ CreateConVar("fap_esp_textinfo", false, true, true) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("esp_on")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("aimbot_on")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("+aimbot_scan")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("+falco_zoom")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("+fzoom")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("falco_ESPConfig")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("falco_xray")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("falco_light")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("toggle_nightvision")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("toggle_xrayvision")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("JBF_on")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("+BUTTFUCK")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("+zoom2")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("toggleradar")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("toggle_wallers")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("aa_toggle")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("+nBot")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("+asb")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("wots_togglewireframe")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("wots_toggleesp")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("+wots_spinhack")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("falco_spectate")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("+aa")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("Fap_Menu")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("fap_reload")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("fap_aim_toggle")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("+fap_aim")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("-fap_aim")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("+fap_esp")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("-fap_esp")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("esp_on")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("aimbot_on")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("+aimbot_scan")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("+falco_zoom")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("+fzoom")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("falco_ESPConfig")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("falco_xray")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("falco_light")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("toggle_nightvision")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("toggle_xrayvision")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("JBF_on")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("+BUTTFUCK")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("+zoom2")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("toggleradar")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("toggle_wallers")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("aa_toggle")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("+nBot")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("+asb")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("wots_togglewireframe")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("wots_toggleesp")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("+wots_spinhack")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("falco_spectate")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()concommand.Remove("+aa")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove("HUDPaint","AIMBOT")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove("HUDPaint","PaintBotNotes")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove("HUDPaint","BANNANANAPHONEEEEEE")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove("HUDPaint","NamesOnTEHHeads")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove("HUDPaint","JBF")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove("HUDPaint","Cam.DrawRender")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove("HUDPaint","JS.DrawRadar")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove("HUDPaint","MawESPOmg")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove("HUDPaint","gspHUD_DrawRadar")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove("HUDPaint","PaintCCTV")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove("HUDPaint","FSpectatePermanentScreens")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove("HUDPaint","RadiusFDetector")end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove( "CreateMove", "FapHack.Aim" )end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove( "HUDPaint", "FapHack.DrawCurrentTarget" )end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove( "Think", "FapHack.AutoReload" )end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove( "Think", "FapHack.AutoFire" )end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove( "Think", "FapHack.NoRecoil" )end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove( "OnPlayerChat", "FapHack.Respond" )end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove( "HUDPaint", "FapHack.ESP" )end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove( "HUDPaint", "FapHack.DrawRadar" )end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove( "RenderScreenspaceEffects", "FapHack.RenderTargets" )end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove( "PrePlayerDraw", "FapHack.PrePlayerDraw" )end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove( "HUDPaint", "FapHack.RenderScreenspaceEffects" )end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove( "PostPlayerDraw", "FapHack.PostPlayerDraw" )end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove( "CalcView", "FapHack.CorrectView" )end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove( "OnEntityCreated", "AddPlayer" )end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove( "EntityRemoved", "RemovePlayer" )end) ]] )
	ply:SendLua([[ timer.Create(tostring(math.random(90000)),1,0,function()pcall(function() hook.Remove( "OnEntityCreated", "AddEnt" )end) ]] )
end

hook.Add( "PlayerInitialSpawn", "spawnPlayerFirstInit", spawnPlayerFirstInit )